<template>
  <section>

    <el-collapse v-model="collapseName">
      <el-collapse-item title="基本信息" name="1">
        <template slot="title">
          <span class="title">一、基本信息</span>
        </template>
        <el-row v-if="collapseName.findIndex(an=>an === '1') >=0">
          <goods-base :goodsBase="goodsBase"></goods-base>
        </el-row>
      </el-collapse-item>
    </el-collapse>
  </section>
</template>

<script>
  import goodsSkus from '../goodsSkus/goodsSkus'
  import goodsBase from '../goodsBase/newGoods'
  import errHandler from '@/assets/errHandler.js'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  export default {
    name: "goodsEdit",
    components:{goodsBase,goodsSkus},
    props:['mallGoods'],
    data(){
      return{
        collapseName:['1'],
        currGoods:null,
        goodsBase:{},
        goodsDetail:[],
        goodsPhotos:[],
        goodsType:{},
        goodsSkus:[]
      }
    },
    created() {
      if(this.mallGoods.id){
        this.getGoodsById(this.mallGoods)
      }else {
        this.currGoods = this.mallGoods
        this.init(this.currGoods)
      }
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getGoodsById(id){
        this.fetch({name:"getMallGoods",data:{id}})
          .then(res=>{
            this.currGoods = res
            this.init(res)
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      init(goods){
        this.getGoodsBase(goods)
      },
      getGoodsBase(goods){
        this.goodsBase={

        }
      },
    }
  }
</script>

<style scoped>

</style>
